package edu.neu.agv_backend.controller;

import edu.neu.agv_backend.dto.AjaxResult;
import edu.neu.agv_backend.dto.AgvTaskDto;
import edu.neu.agv_backend.dto.TableDataInfo;
import edu.neu.agv_backend.service.TaskFromDBService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/agv/task/db")
public class TaskFromDBController {

    private final TaskFromDBService taskFromDBService;

    public TaskFromDBController(TaskFromDBService taskFromDBService) {
        this.taskFromDBService = taskFromDBService;
    }

    @GetMapping("/list")
    public TableDataInfo<AgvTaskDto> listTask(@RequestParam(defaultValue = "1") int pageNum,
                                              @RequestParam(defaultValue = "10") int pageSize) {
        return taskFromDBService.listTask(pageNum, pageSize);
    }

    @GetMapping("/{id}")
    public AjaxResult<AgvTaskDto> getTask(@PathVariable Long id) {
        return taskFromDBService.getTask(id);
    }

    @PostMapping
    public AjaxResult<Void> addTask(@RequestBody AgvTaskDto dto) {
        return taskFromDBService.addTask(dto);
    }

    @PutMapping
    public AjaxResult<Void> updateTask(@RequestBody AgvTaskDto dto) {
        return taskFromDBService.updateTask(dto);
    }

    @DeleteMapping("/{id}")
    public AjaxResult<Void> delTask(@PathVariable Long id) {
        return taskFromDBService.delTask(id);
    }

    @PostMapping("/start/{id}")
    public AjaxResult<Void> startTask(@PathVariable Long id) {
        return taskFromDBService.startTask(id);
    }

    @PostMapping("/end/{id}")
    public AjaxResult<Void> endTask(@PathVariable Long id, @RequestParam(defaultValue = "false") boolean isAbort) {
        return taskFromDBService.endTask(id, isAbort);
    }

    @GetMapping("/preupload/{id}")
    public AjaxResult<Void> preUploadTask(@PathVariable Long id) {
        return taskFromDBService.preUpload(id);
    }

    @PostMapping("/upload/{id}")
    public AjaxResult<Void> uploadTask(@PathVariable Long id) {
        return taskFromDBService.upload(id);
    }
} 